**********************
**********************
*LABORATORY SESSION 3*
**********************
**********************

//Sampling
% task-a:
% x_a(t) = Asin(2pi F t), Fs = 1/T;
% -> x_a(nT) = x(n) = Asin(2pi F nT) = Asin((2pi n F)/Fs)

% task-b: 
Fs = 8000; % 8000 samples in 1 second => 24000 samples in 3 seconds
n = 0:23999;
% x(n) = Acos(2pi n F/Fs + theta)
x1 = 3*cos(2*pi*220/8000*n);
x2 = 0.7*cos(2*pi*880/8000*n);
x3 = x1 + x2; 
s = n/Fs; % in seconds

figure;
hold on;
plot(s,x1);plot(s,x2); plot(s,x3);
hold off;

soundsc(x1,8000);
soundsc(x2,8000);
soundsc(x3,8000);


//Generating tones 
% Note frequencies can be found at following webpage http://www.phy.mtu.edu/~suits/notefreqs.html
% (the common one that we use are subscript with number 4)
task-a:
Fs = 8000;
n = 0:7999; %the length of the note, in this case the length is 1 second
% note = sin(2pi n F/Fs)
c1 = sin(2*pi*n*32.70/Fs);
c2 = sin(2*pi*n*65.41/Fs);
c3 = sin(2*pi*n*130.81/Fs);
soundsc([c1 c2 c3],Fs); 

task-b:
% Song Kuza pazi
Fs = 8000;
n1 = 0:3999;
n2 = 0:7999;

c4 = sin(2*pi*261.63*n1/Fs);
d4 = sin(2*pi*293.66*n1/Fs);
e4 = sin(2*pi*329.63*n1/Fs);
c4_last = sin(2*pi*261.63*n2/Fs);

melody = [c4 c4 c4 c4 d4 d4 d4 d4 e4 e4 d4 d4 c4 c4 c4_last];
soundsc(melody, Fs);


// Nyquist
task-a:
% x_a(t) = 3cos(2pi 50 t)
% -> F = 50Hz => Fs >= 2Fmax => Fs=100Hz
% x_a(t)=Acos(2pi F t + theta) ---> x(n) = Acos(2pi F/Fs n + theta)
% ->  if Fs = 200Hz => discrete-time signal is x(n) = 3cos(100pi/200n) = 3cos(pi/2n)

task-b: 
% x_a(t) = cos(50pi t) + 10cos(300pi t)
% x_a(t) = Acos(2pi F t + theta)
% -> F1 = 25Hz, F2 = 150Hz = Fmax => FN = 2Fmax = 300Hz





